﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BL
{
    public class Jurnaly
    {
        static Jurnaly instance;
		public static Jurnaly Instance
		{
			get { return instance; }
		}

		List<JurnalItem> items = new List<JurnalItem>();
        

        public Jurnaly(List<JurnalItem> jurnalItems)
		{
			instance = this;
            foreach (JurnalItem ji in jurnalItems)
            {
                items.Add(ji);
                
            }            
		}

        public JurnalItem[] Items
		{
			get { return items.ToArray(); }
		}
        public void Add(JurnalItem jurnal)
        {
            items.Add(jurnal);            
        }
        public void Delete(string id)
        {
            JurnalItem ji = this[id];
            items.Remove(ji);
        }

        public JurnalItem this[string id]
        {
            get
            {
                foreach (JurnalItem ji in items)
                {
                    if (ji.Id == id)
                        return ji;
                }
                return null;
            }
            set
            {
                for (int i = 0; i < items.Count; i++)
                {
                    if (items[i].Id == id)
                    {
                        items[i] = value;
                        return;
                    }
                }
            }
        }
    }
}
